<?php
namespace Admin\Controller;
use Think\Controller;
class GreateController extends Controller {

	public function greateintroduce(){

        $greatintr=M('greatintr');
        $list = $greatintr->select();
        // var_dump($list);
          
        foreach($list as $key=>$value)
        { 
            foreach($value as $key2=>$value2)
            { 

                if($key2=='teacher_id')
                {
                    $listg[$key]['gid'] = $list[$key]['greatintr_id'];
                    $listg[$key]['focus'] = $list[$key]['focus_people'];

                    $teacher=M('teacher');
                    $tid = $list[$key]['teacher_id'];
                    $list2 = $teacher->where("teacher_id=$tid")->select();
                    $listg[$key]['tname'] = $list2['0']['teacher_name'];
                    $listg[$key]['tintr'] = $list2['0']['teacher_intr'];

                    $clubintr=M('clubintr');
                    $cid = $list[$key]['clubintr_id'];
                    $list3 = $clubintr->where("clubintr_id=$cid")->select();
                    $listg[$key]['cname'] = $list3['0']['club_name'];
                    $this->assign('data',$listg);// 赋值数据集
                    // var_dump($listg);
                }
            }
        } 
        
     	$this->display();
    }


    //大师简介编辑页面
    public function greatedit(){

        $id=$_GET['id'];
        $intr=M('greatintr');
        $list = $intr->where("greatintr_id = $id ")->select();
        foreach($list as $key=>$value)
        { 
            foreach($value as $key2=>$value2)
            { 

                if($key2=='teacher_id')
                {
                    $listg[$key]['gid'] = $list[$key]['greatintr_id'];
                    $listg[$key]['focus'] = $list[$key]['focus_people'];

                    $teacher=M('teacher');
                    $tid = $list[$key]['teacher_id'];
                    $list2 = $teacher->where("teacher_id=$tid")->select();
                    $listg[$key]['tname'] = $list2['0']['teacher_name'];
                    $listg[$key]['tintr'] = $list2['0']['teacher_intr'];

                    $clubintr=M('clubintr');
                    $cid = $list[$key]['clubintr_id'];
                    $list3 = $clubintr->where("clubintr_id=$cid")->select();
                    $listg[$key]['cname'] = $list3['0']['club_name'];
                    $this->assign('data',$listg);// 赋值数据集
                    // var_dump($listg);
                }
            }
        } 
        $this->display();
    }

    //修改大师简介编辑页面
    public function dogreatedit(){

        $greatintr_id = I('post.gid');
        $tname = I('post.gname');
        $tintr = I('post.tintr');
        $cname = I('post.cname');
        $focus = I('post.focus');

        $intr=M('greatintr');
        $list = $intr->where("greatintr_id = $greatintr_id ")->select();
        $data['focus_people'] = $focus;
        $result1 = $intr->where("greatintr_id = $greatintr_id ")->save($data);
        
        $tid = $list['0']['teacher_id'];
        $intrt = M('teacher');
        $data1['teacher_name'] = $tname;
        $data1['teacher_intr'] = $tintr;
        $result2 = $intrt->where("teacher_id=$tid")->save($data1);
         
        $cid = $list['0']['clubintr_id'];
        $intrc = M('clubintr');
        $data2['club_name'] = $cname;
        $result3 = $intrc->where("clubintr_id=$cid")->save($data2);
        
         
        if($result1==FALSE&&$result2==FALSE&&$result3==FALSE){
            $this->error("修改失败！");
        }else{
            $this->success("修改成功！");
        }
    }
    
    //删除大师简介信息
    public function greatdelete(){

        $greatintr_id=$_GET['id'];
        //var_dump($clubintr_id);
        $greatintr=M('greatintr');

        if($greatintr->where("greatintr_id=$greatintr_id")->delete())
        {
            $this->success('删除成功',U('Greate/cgreateintroduce'));
        }
        else{

            $this->error('删除失败');
        }
    }

    //大师课堂视频列表
    public function greatevideo(){
 
        $coursevideo=M('coursevideo');
        $list = $coursevideo->select();
        foreach($list as $key=>$value)
        { 
            foreach($value as $key2=>$value2)
            { 
                if($key2=='greatintr_id'){
                    
                    $listg[$key]['vcourse_id'] = $list[$key]['vcourse_id'];
                    $listg[$key]['vcourse_content'] = $list[$key]['vcourse_content'];
                    $listg[$key]['vcourse_place'] = $list[$key]['vcourse_place'];
                    $listg[$key]['vcourse_focus'] = $list[$key]['vcourse_focus'];

                    $teacher=M('teacher');
                    $tid = $list[$key]['greatintr_id'];
                    $list3 = $teacher->where("teacher_id=$tid")->select();
                    $listg[$key]['tname'] = $list3['0']['teacher_name'];
                    $this->assign('data',$listg);// 赋值数据集

                }
            }
        }
        $this->display();
    }
    
    //删除大师课程视频
    public function gvideodelete(){

        $vcourse_id=$_GET['id'];
        //var_dump($clubintr_id);
        $coursevideo=M('coursevideo');

        if($coursevideo->where("vcourse_id=$vcourse_id")->delete())
        {
            $this->success('删除成功',U('Greate/greatevideo'));
        }
        else{

            $this->error('删除失败');
        }
    }

    //跳转大师视频添加页面
    public function greatevideoadd(){

        $this->display();
    }

    //添加大师课程信息
    public function dogreatevideoadd(){

        $greatintrid = I('post.greatintrid');
        $vcourseplace = I('post.vcourseplace');
        $vcoursecontent = I('post.vcoursecontent');
        $vcoursefocus = I('post.vcoursefocus');

        //保存数据到data数组
        $data['greatintr_id'] = $greatintrid ;
        $data['vcourse_content'] =  $vcourseplace;
        $data['vcourse_place'] = $vcoursecontent;
        $data['vcourse_focus'] = $vcoursefocus;
    
        $coursevideo=M('coursevideo');
        $result = $coursevideo->add($data);
        if($result==FALSE){
            $this->error("添加失败！");
        }else{
            $this->success("添加成功！");
        }
    }

    //跳转大师提问信息列表
    public function greatequestion(){

        $gquestion=M('gquestion');
        $list = $gquestion->select();
        foreach($list as $key=>$value)
        { 
            foreach($value as $key2=>$value2)
            { 

                if($key2=='usr_id')
                {
                    $listg[$key]['gqid'] = $list[$key]['gquestion_id'];
                    $listg[$key]['g_response'] = $list[$key]['g_response'];
                    $listg[$key]['g_ask'] = $list[$key]['g_ask'];

                    $users=M('users');
                    $uid = $list[$key]['usr_id'];
                    $list2 = $users->where("usr_id=$uid")->select();
                    $listg[$key]['uname'] = $list2['0']['user_name'];
                    

                    $teacher=M('teacher');
                    $tid = $list[$key]['greatintr_id'];
                    $list3 = $teacher->where("teacher_id=$tid")->select();
                    $listg[$key]['tname'] = $list3['0']['teacher_name'];
                    $this->assign('data',$listg);// 赋值数据集
                   
                }
            }
        } 
        $this->display();
    }
    
    //删除大师提问列表信息
    public function gqdelete(){

        $gquestion_id=$_GET['id'];
        //var_dump($clubintr_id);
        $gquestion=M('gquestion');

        if($gquestion->where("gquestion_id=$gquestion_id")->delete())
        {
            $this->success('删除成功',U('Greate/greatequestion'));
        }
        else{

            $this->error('删除失败');
        }
    }

    
}